const BaseHandler = require('../base-handler');
const SystemServices = require('../../../constants').SystemServices;
const HTTP_VERBS = require('../../../constants').HTTP_VERBS;

class   QiniuOperationHandler extends BaseHandler {
    get pattern() {
        return "/qiniu/operation/:type";
    }

    doGET(request, response) {

        this.Controller.operateQiniu({wxUid: '25714b2d-40c8-4d86-b8e8-c0954dc75982', wxSid:'123'}, (result) => {
            if (result.error) {
                return response.json({
                    success: false,
                    error: result.error
                });
            }
            response.json({
                success: true,
                result: result
            });
        })
    }

    doPOST(request, response) {
        if (!request.session.user.authenticated) {
            response.json({
                success: false,
                error: '请登录系统后再调用此接口！'
            });
        } else {
            var data = {
                type: request.params.type,
                data: request.body
            };
        
        this.Controller.operateQiniu(data, (result) => {
            if (result.error) {
                return response.json({
                    success: false,
                    error: result.error
                });
            }
            response.json({
                success: true,
                result: result
            });
        })
    }
}

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
        this.registerVerb(HTTP_VERBS.POST, this.doPOST)
    }
}

module.exports = QiniuOperationHandler;


